﻿<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
    xmlns:dssp="http://schemas.microsoft.com/xw/2004/10/dssp.html"
    xmlns:i2c="http://www.robot-electronics.co.uk/2006/10/i2chardware.html"
    >

  <xsl:import href="/resources/dss/Microsoft.Dss.Runtime.Home.MasterPage.xslt" />

  <xsl:template match="/">
    <xsl:comment>
      <!-- Service Header Info -->
    </xsl:comment>
    <xsl:variable name="title">
      I2C Hardware Service
    </xsl:variable>
    <xsl:variable name="serviceName">
      I2C Hardware Service
    </xsl:variable>
    <xsl:variable name="description">
      The I2C Hardware service controls either the USBI2C (Stop Bits: Two) or the RF04/CM02 (Stop Bits: One), to allow access to the I2C bus and implement the Generic I2C contract.<br/><br/>
      Press Scan to search the I2C bus for devices and optionaly start related services.
    </xsl:variable>

    <xsl:call-template name="MasterPage">
      <xsl:with-param name="serviceName" select="$serviceName" />
      <xsl:with-param name="description" select="$description" />
      <!-- If title is not provided, serviceName will be used instead. -->
      <xsl:with-param name="title">
        <xsl:value-of select="$serviceName" />
        <xsl:if test="$title != ''">
          <xsl:text> - </xsl:text>
          <xsl:value-of select="$title" />
        </xsl:if>
      </xsl:with-param>
      <!-- Possible values for navigation are: 'Open', 'Closed', and 'None'
           'Open' is the default value. -->
      <xsl:with-param name="navigation" select="'Open'" />
      <!-- The contents of head param will be placed just before the </head> tag in html. -->
      <xsl:with-param name="head">
        <link rel="stylesheet" type="text/css" href="/resources/I2CHardware/Devantech.Services.I2C.Hardware.resources.DevantechI2CHardware.Stylesheet.css" />

        <style type="text/css">
          /* Service-specific stylesheet goes here */

        </style>
        <script language="javascript" type="text/javascript">
          <![CDATA[<!--

/* Service-specific script goes here */

dssRuntime.init = function()
{
  // Add page initialization code here.
  // This function is attached to the window.onload event.
  // Do not override window.onload.
}

//-->     ]]>
        </script>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <!-- Match service state's document element. -->
	<xsl:template match="/i2c:StateType">
			
				<!--span class="PageName">I2C Hardware Service <img src="/resources/I2CHardware/Devantech.Services.I2C.Hardware.resources.DevantechI2CHardware.Image.png"/></span-->

				<div class="Module">
					<div class="RightColumn">
						<table class="Config">
							<tr>
								<th colspan="2">
									Config
								</th>
							</tr>
							<tr>
								<td class="SmallText">
									Com Port
								</td>
								<td class="SmallText">
									<form method="POST" >
										<xsl:attribute name="id">ComPortForm</xsl:attribute>
										<input  class="Editable" maxlength="5" name="ComPort" onblur="this.className='Editable';document.getElementById(this.id + 'Form').submit();"
											onfocus="this.className='EditableActive'" title="Click to change delay between polling"
											type="text" >
											<xsl:attribute name="id">ComPort</xsl:attribute>
											<xsl:attribute name="value">
												<xsl:value-of select="i2c:ComPort" />
											</xsl:attribute>
										</input>
									</form>
								</td>
							</tr>

							<tr>
								<td class="SmallText">
									Stop Bits
								</td>
								<td>
									<form method="POST" >
										<xsl:attribute name="id">StopBitsValueForm</xsl:attribute>
										<select  class="Editable" maxlength="5" name="StopBitsValue" onChange="document.getElementById(this.id + 'Form').submit();"
											id="StopBitsValue"  title="Click to change delay between polling"
											type="text" >
											<xsl:choose>
												<xsl:when test="i2c:StopBitsValue = 'One'">
													<option value="One" selected="selected">One</option>
													<option value="Two">Two</option>
													</xsl:when>
												<xsl:otherwise>
													<option value="One">One</option>
													<option value="Two" selected="selected">Two</option>
												</xsl:otherwise>
											</xsl:choose>
										</select>
									</form>
								</td>
							</tr>

							
						</table>
					</div>
					
					
					<span class="SubTitle">Com Port</span>
					<br/>
					<span class="key">
						Port Speed:
					</span>
					<span class="value">
						<xsl:value-of select="i2c:PortSpeed"/>
					</span>
					<br/>
					<span class="key">
						Parity:
					</span>
					<span class="value">
						<xsl:value-of select="i2c:ParityValue"/>
					</span>
					<br/>
					<span class="key">
						DataBits:
					</span>
					<span class="value">
						<xsl:value-of select="i2c:DataBits"/>
					</span>
					<br/>
					
					<span class="key">
						Last Contact:
					</span>
					<span class="value">
						<xsl:value-of select="i2c:LastContact"/>
					</span>
					<br/>
					<br/>
				</div>
				<div class="Module">
					<div class="RightColumn">
						<table class="Config">
							<tr>
								<th colspan="2">
									Monitoring
								</th>
							</tr>
							<tr>
								<td class="SmallText">
									Enable
								</td>
								<td class="SmallText">
									<form method="POST">
										<xsl:attribute name="id">EnableHealthMonitoringForm</xsl:attribute>
										<input type="hidden" name="EnableHealthMonitoringChange" value="true"/>

										<input name="EnableHealthMonitoring" onclick="document.getElementById(this.id + 'Form').submit();"
											title="Click to enable Polling of the sensor" type="checkbox">
											<xsl:attribute name="id">EnableHealthMonitoring</xsl:attribute>
											<xsl:if test="i2c:EnableHealthMonitoring = 'true'">
												<xsl:attribute name="checked">CHECKED</xsl:attribute>
												<xsl:attribute name="value">on</xsl:attribute>
											</xsl:if>
										</input>
									</form>
								</td>
							</tr>

							<tr>
								<td class="SmallText">
									Auto Start Services
								</td>
								<td>
									<form method="POST">
										<xsl:attribute name="id">StartHardwareServicesForm</xsl:attribute>
										<input type="hidden" name="StartHardwareServicesChange" value="true"/>

										<input name="StartHardwareServices" onclick="document.getElementById(this.id + 'Form').submit();"
											title="Click to enable Polling of the sensor" type="checkbox">
											<xsl:attribute name="id">StartHardwareServices</xsl:attribute>
											<xsl:if test="i2c:StartHardwareServices = 'true'">
												<xsl:attribute name="checked">CHECKED</xsl:attribute>
												<xsl:attribute name="value">on</xsl:attribute>
											</xsl:if>
										</input>
									</form>
								</td>
							</tr>

							<tr>
								<td colspan="2">
									<xsl:choose>
										<xsl:when test="i2c:IsScanning = 'false'">
											<form method="POST" id="ScanForm">
												<input type="hidden" name="Scan" value="true"/>
												<a href="javascript:void(0)" onClick="document.getElementById('ScanForm').submit();">Scan I2C bus...</a>
											</form>
										</xsl:when>
										<xsl:otherwise>
											SCANNING
										</xsl:otherwise>
									</xsl:choose>
									
								</td>
							</tr>
						</table>
					</div>
					<span class="SubTitle">Recent Devices</span>
					<table>
						<tr>
							<th>Address</th>
							<th>Name</th>
							<th>Type</th>
							<th>Service</th>
							<xsl:if test="i2c:EnableHealthMonitoring = 'true'">
								<th>Reads</th>
								<th>Writes</th>
								<th>Errors</th>
							</xsl:if>

						</tr>

						<xsl:for-each select="i2c:RecentModules/*">
							<tr>
								<td>
									<span class="value">
										<xsl:value-of select="i2c:I2CAddress"/>
									</span>
								</td>
								<td>
									<span class="value">
										<xsl:value-of select="i2c:Name"/>
									</span>
								</td>
								<td>
									<span class="value">
										<xsl:value-of select="i2c:ModuleTypeName"/>
									</span>
								</td>
								<td>
									<span class="value">
										<xsl:choose>
											<xsl:when test ="i2c:ActiveService = ''">
												<form method="POST">
													<xsl:attribute name="id">CreateServiceForm<xsl:value-of select="position()" /></xsl:attribute>
													<input type="hidden" name="ServiceContract">
														<xsl:attribute name="value"><xsl:value-of select="i2c:ModuleContract"/></xsl:attribute>
													</input>
													<a href="javascript:void(0)" onClick="document.getElementById('ScanForm').submit();">
														<xsl:attribute name="onClick">document.getElementById('CreateServiceForm<xsl:value-of select="position()" />').submit();</xsl:attribute>
														Create Service...
													</a>
												</form>
											</xsl:when>
											<xsl:otherwise>
												<a>
													<xsl:attribute name="href" ><xsl:value-of select="i2c:ActiveService" /></xsl:attribute>
													<xsl:value-of select="i2c:ActiveService" />
												</a>
											</xsl:otherwise>
										</xsl:choose>
										<xsl:value-of select="i2c:Partnered"/>
									</span>
								</td>
								<xsl:if test="//i2c:EnableHealthMonitoring = 'true'">
								<td>
									<span class="value">
										<xsl:value-of select="i2c:ReadCount"/>
									</span>
								</td>
								<td>
									<span class="value">
										<xsl:value-of select="i2c:WriteCount"/>
									</span>
								</td>
								<td>
									<span class="value">
										<xsl:value-of select="i2c:ErrorCount"/>
									</span>
								</td>
								</xsl:if>
								
							</tr>
						</xsl:for-each>
					</table>
					
				</div>
				
				<br clear="all" />
				<div class="hr"></div>
				<div class="RightColumn">
					<a class="LinkSmall" 
						href="http://www.robot-electronics.co.uk/htm/usb_i2c_tech.htm" 
						target="_new">View Documentation...</a>
				</div>
        Config at: /store/Devantech.Services.I2C.Hardware.xml
	</xsl:template>
</xsl:stylesheet>
